#ifndef USER_PLUGIN_DUMMY
#define USER_PLUGIN_DUMMY
#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include "../../../libpland/lib/plugin.hpp"

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#include <boost/thread.hpp>



using namespace std;


class CoreC_Scaler : public UserC_Plugin
{
public:
	CoreC_Scaler();
	~CoreC_Scaler();
	void start();
	void stop();
	void load_queues(CoreC_DQueue * front ,CoreC_DQueue * back);
private:
	CoreC_DQueue *_front;
	CoreC_DQueue *_back;
	bool _running;

};

#endif


CoreC_Scaler::CoreC_Scaler()
{
	_running = false;
}

void CoreC_Scaler::start()
{
	_running = true;
	CoreC_Data * pcm = NULL;
	CoreC_Settings * set = CoreC_Settings::Instance();
	if(!set->isSet("stream.volume0"))
	{
		set->setSetting("stream.volume0", "100");
	}
	if(!set->isSet("stream.volume1"))
	{
		set->setSetting("stream.volume1", "100");
	}
	while(_running)
	{
		float volume_left = utill_to_int(set->getSetting("stream.volume0"))/100.0;
		float volume_right = utill_to_int(set->getSetting("stream.volume1"))/100.0;
		short int* samples;
		pcm = _front->pop();
		samples = (short int*)pcm->get_data();
		for(int i = 0; i < pcm->get_header()->_size/2; i++)
		{
			if(i%2)
				samples[i] = samples[i]*volume_left;
			else
				samples[i] = samples[i]*volume_right;
		}
		_back->push(pcm);
	}
}

void CoreC_Scaler::stop()
{
	_running = false;

}

void CoreC_Scaler::load_queues(CoreC_DQueue* front ,CoreC_DQueue* back)
{
	_front  = front;
	_back  = back;
}


extern "C"
{
	UserC_Plugin* Core_GetInstance()
	{
		return new CoreC_Scaler();
	}

	void Core_KillInstance(UserC_Plugin* a)
	{
		delete a;
	}
}
